#include "stdafx.h"
#include "CPlatformWin32.h"
#include "CWindowWin32.h"

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
CPlatform::CPlatform()
{
	WNDCLASSEXW wcex;
	wcex.cbClsExtra = 0;
	wcex.cbSize = 0;
	wcex.cbWndExtra = 0;
	wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcex.hIconSm = wcex.hIcon;
	wcex.hInstance = (HINSTANCE)GetModuleHandle(nullptr);
	wcex.lpfnWndProc = WndProc;
	wcex.lpszClassName = _T("class_xujie");
	wcex.lpszMenuName = nullptr;
	wcex.style = WS_OVERLAPPEDWINDOW;
	RegisterClassEx(&wcex);
}
CPlatform::~CPlatform()
{

}
IUISystem * CPlatform::GetUISystem()
{
	return &m_uiSystem;
}
IWindow * CPlatform::CreatePlatformWindow()
{
	CWindow * pWnd = new CWindow();
	pWnd->Create();
	return pWnd;
}
IWindow * CPlatform::CreatePlatformWindow(int_32 iX, int_32 iY, uint_32 uiWidth, uint_32 uiHeight)
{
	CWindow * pWnd = new CWindow();
	pWnd->Create(iX, iY, uiWidth, uiHeight);
	return pWnd;
}



static void OnCreate(HWND hWnd)
{

}
static void OnDestroy(HWND hWnd)
{

}

static void OnPaint(HWND hWnd)
{
	PAINTSTRUCT ps = {0};
	HDC hdc = BeginPaint(hWnd, &ps);
	EndPaint(hWnd, &ps);
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_LBUTTONDOWN:
		SetCapture(hWnd);
		break;
	case WM_LBUTTONUP:
		ReleaseCapture();
		break;
	case WM_CREATE:
		OnCreate(hWnd);
		break;
	case WM_DESTROY:
		OnDestroy(hWnd);
		PostQuitMessage(0);
		break;
	case WM_PAINT:
		OnPaint(hWnd);
		break;
	case WM_KEYDOWN:
		switch(wParam)
		{
		case VK_ADD:
			break;
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}